package com.medeolinx.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.medeolinx.model.ModelManager;

/**
 * handle GxTerrain related url
 * 
 * @author chenqingqing
 */
@Controller
public class TerrainController {
	private static class Links {
		static final String ADD_COMMENT = "/comment_add";
	}

	// private static class ViewPages {
	// static String REDIRECT_LOGIN = "redirect:/index.html";
	// static String TERRAIN = "terrain";
	// }

	@Autowired(required = true)
	private ModelManager modelManager;

	@RequestMapping(value = Links.ADD_COMMENT)
	public @ResponseBody
	String addComment(@RequestParam("user") String username, @RequestParam("terrain_id") int tnId, @RequestParam("comment") String comment) {
		try {
			if (modelManager.addComment(username, tnId, comment)) {
				return "true";
			} else {
				return "false";
			}
		} catch (Throwable e) {
			e.printStackTrace();
			return "false";
		}
	}
}
